package com.yorick.authority.controller;

import com.yorick.authority.modal.request.BaseListRequest;
import com.yorick.authority.modal.request.ipWhiteList.IPWhiteListAddRequest;
import com.yorick.authority.modal.request.ipWhiteList.IPWhiteListDeleteRequest;
import com.yorick.authority.modal.request.ipWhiteList.IPWhiteListDetailRequest;
import com.yorick.authority.modal.request.ipWhiteList.IPWhiteListEditRequest;
import com.yorick.authority.modal.response.BaseListResponse;
import com.yorick.authority.service.IPWhiteListService;
import com.yorick.common.Result.SimpleFactory.ResultFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

/**
 * @program: IPWhiteListController
 * @description: IP白名单管理
 * @author: Yorick
 * @create: 25/7/2022
 **/
@Slf4j
@Controller
@RequestMapping("ipWhiteList")
public class IPWhiteListController {
    @Resource
    IPWhiteListService ipWhiteListService;

    @RequestMapping(value = "ipWhiteList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String, Object> ipWhiteList(@Valid @RequestBody BaseListRequest requestBody) {
        BaseListResponse result = ipWhiteListService.getIPWhiteList(requestBody);
        return ResultFactory.success(result).display();
    }

    @RequestMapping(value = "addIPWhiteList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String, Object> addIPWhiteList(@Valid @RequestBody IPWhiteListAddRequest requestBody) {
        return ipWhiteListService.addIPWhiteList(requestBody);
    }

    @RequestMapping(value = "editIPWhiteList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String, Object> editIPWhiteList(@Valid @RequestBody IPWhiteListEditRequest requestBody) {
        return ipWhiteListService.editIPWhiteList(requestBody);
    }

    @RequestMapping(value = "ipWhiteListDetail", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String, Object> ipWhiteListDetail(@Valid @RequestBody IPWhiteListDetailRequest requestBody) {
        return ResultFactory.success(ipWhiteListService.ipWhiteListDetail(requestBody)).display();
    }

    @RequestMapping(value = "deleteIPWhiteList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String, Object> deleteIPWhiteList(@Valid @RequestBody IPWhiteListDeleteRequest requestBody) {
        return ipWhiteListService.deleteIPWhiteList(requestBody);
    }
}
